{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div id="toolbar" class="row">
    <div class="col-sm-12 m-b-xs">
        <button type="button" class="btn-sm btn-warning" onclick="wechat_fans.sync()">
            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>同步粉丝
        </button>
        <button type="button" class="btn-sm btn-danger" onclick="wechat_fans.addblack()">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>加入黑名单
        </button>
    </div>
</div>
<!--工具栏 end-->
{/block}
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="table" ></table>
</div>
{/block}
{block name="script"}
<script src="__STATIC__/admin/plugins/table-export/tableExport.min.js"></script>
<script src="__STATIC__/admin/plugins/bootstrap-table/extensions/export/bootstrap-table-export.min.js"></script>
<script type="text/javascript">
    $("input[class='form-control']").keypress(function (e) {
        var e = e || window.event;
        if (e.keyCode == 13) {
            $(".btn.btn-info").click();
        }
    });
    window.wechat_fans = {
        //定义工具栏
        sync: function(){ //同步
            $.ajax({
                type: 'post',
                url: "{:url('admin/wechatFans/sync')}",
                data: {},
                dataType:"json",
                beforeSend: function(){
                    load_index = parent.layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                },
                success: function(data){
                    parent.layer.close(load_index);
                    layer.msg(data.msg);
                },
                error: function(data){
                    layer.msg(data.responseText);
                }
            });
        },
        tagset: function(id){ //添加粉丝标签
            parent.layer.open({
                type: 2,
                title: '{$title} > 添加标签',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("admin/wechatFans/tagSet")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        addblack: function(){ //加入黑名单
            var ids = $.map($("#table").bootstrapTable('getSelections'),function(row){
                return row.id;
            });
            if(ids.length == 0){
                layer.msg("请先选择拉黑的粉丝!");
                return false;
            }
            layer.confirm('确认要加入黑名单吗？',function(){
                $.post('{:url("admin/wechatFans/backAdd")}',{'id':ids.toString()},function(data){
                    if(200 == data.code){
                        //删除行
                        $("#table").bootstrapTable('remove',{field:'id',values:ids});
                    }
                    layer.msg(data.msg);
                })
            })

        },
        //操作格式化
        opert: function(value,row){
            var rst = '';
            // var edit_auth = '{:auth("$classuri/edit")}';
            var tagadd_auth = '{:auth("$classuri/tagadd")}';
            //var del_auth = '{:auth("$classuri/del")}';
            // if(edit_auth) {
            //     rst += '<a onclick="wechat_fans.edit('+row.id+')" class="btn btn-outline btn-default btn-xs">编辑</a> ';
            // }
            if(tagadd_auth) {
                rst += '<a onclick="wechat_fans.tagset('+row.id+')" class="btn btn-outline btn-default btn-xs">添加标签</a> ';
            }
            // if(del_auth) {
            //     rst += '<a onClick="$.Oa.delete(this,false,false)" data-href="{:url(\'admin/wechatTags/del\')}" data-id="'+row.id+'" class="btn btn-outline btn-danger btn-xs">删除</a> ';
            // }
            return rst;
        }
    }
    $('#table').bootstrapTable({
        toolbar: "#toolbar",
        search:true,
        showColumns: true,
        showRefresh: false,
        showExport: true,                     //是否显示导出
        exportDataType: "basic",              //basic', 'all', 'selected'.
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"admin/wechatFans/index\")}",
        pageNumber: 1, //初始化加载第一页，默认第一页
        pagination:true,//是否分页
        sortOrder: 'desc',
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            var querys = {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
            if(params.searchText != ''){
                querys.name = params.searchText;
            }
            return querys;
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {checkbox:true,width: 20},
            {field:'id',title:'ID',width: 20},
            {field:'headimgurl',title:'头像',width: 80,formatter:function(value){
                return '<img src='+value+' width="30" />';
            }},
            {field:'nickname',title:'昵称',width: 80},
            {field:'sex',title:'性别',width: 80,formatter:function(value){
                    var sex = ['未知','男','女'];
                    return sex[value];
                }},
            {field:'tag_list',title:'粉丝标签',width: 80},
            {field:'country',title:'国家',width: 80},
            {field:'province',title:'省份',width: 80},
            {field:'city',title:'城市',width: 80},
            {field:'action',title:'操作',width: 80,formatter:wechat_fans.opert},
        ]
    })
</script>
{/block}